package org.teststack.utils;

import org.testng.Assert;

import java.sql.*;

public class ConMysql {



    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        String url = ReadConf.readConf("jdbc-url");
        String username = ReadConf.readConf("username");
        String password = ReadConf.readConf("password");

        Connection conn = DriverManager.getConnection(url, username, password);


            String select_sql = "select * from QCDZ_MC_SL_MCBYJL where  entname like '%浙江非脚后跟建筑设计事务所有限责任公司%'";
            ResultSet res = exec_select(select_sql);
            String nameid = null;
            while (res.next()) {
                nameid = res.getString("name_id");

                System.out.println(nameid);
            }
//        Assert.assertEquals(dwxz,"10");
//        String update_sql = "select * from QCDZ_LJM_SL_GJJBAXX \n"  + "where  pripid = \'330782020421000050303\'\n";
//        ResultSet resultSet = exec_select(update_sql);
//        String dw = null;
//        while (res.next()) {
//            dw = res.getString("dw");
//
//            System.out.println(dw);
//        }
//        Assert.assertEquals(dw,"10");



        }
        public static Connection connection() throws ClassNotFoundException, SQLException {
            String url = ReadConf.readConf("jdbc-url");
            String username = ReadConf.readConf("username");
            String password = ReadConf.readConf("password");
            Connection connection = null;
            connection = DriverManager.getConnection(url,username,password);


            System.out.println("数据更新/删除成功");
            return connection;

        }






    public static ResultSet exec_select(String sql) throws SQLException , ClassNotFoundException {

        String select_sql = sql;
        //实例化Statement对象执行语句
        Statement statement = connection().createStatement();
        //准备一个结果集保存数据
        ResultSet resultSet = statement.executeQuery(select_sql);
       while (resultSet.next()) {
            String nameid = resultSet.getString("name_id");
//            String entname = resultSet.getString("entname");
            System.out.println(nameid);
//
        }

//        statement.close();
//        connection().close();
        return resultSet;

    }
//    public static ResultSet exec_update(String sql) throws SQLException , ClassNotFoundException {
//
//        String update_sql = sql;
//        //实例化Statement对象执行语句
//        Statement statement = connection().createStatement();
//        //准备一个结果集保存数据
//        ResultSet resultSet = statement.executeQuery(update_sql);
////        while (resultSet.next()) {
////            String pripid = resultSet.getString("pripid");
////            String entname = resultSet.getString("entname");
////            System.out.println(pripid + "\t" + entname);
////
////        }
//
////        statement.close();
////        connection().close();
//        return resultSet;
//
//
//    }

}

